<template>
  <div class="page_padding repair_add">
    <MyNavBar @goback="goback" title="物品维修、更换申请单" />
    <div class="add_con">
      <div class="self_info">
        <div class="self_title_bold">基本信息</div>
        <div class="correlation_info">
          <div class="left">申请人</div>
          <div class="right">{{ userInfo.userName }}</div>
        </div>
        <div class="correlation_info">
          <div class="left">部门名称</div>
          <div class="right">{{ userInfo.loginPostInfo.orgName }}</div>
        </div>
        <div class="correlation_info">
          <div class="left">申请时间</div>
          <div class="right">{{ timeNow }}</div>
        </div>
      </div>
      <div class="con_box">
        <div class="box_head">
          <div class="head_radio">
            <van-radio-group v-model="applyType" direction="horizontal" @change="radioChange">
              <van-radio name="1">维修</van-radio>
              <van-radio name="2">更换</van-radio>
            </van-radio-group>
          </div>
        </div>
        <div class="box_info">
          <div class="info_inpu">
            <div class="info_tit">型号：</div>
            <div class="info_input">
              <van-field
                class="scroe_input"
                v-model="model"
                rows="4"
                autosize
                type="textarea"
                :placeholder="'请输入'"
                maxlength="100"
                show-word-limit />
            </div>
          </div>
          <div class="info_inpu">
            <div class="info_tit">事由：</div>
            <div class="info_input">
              <van-field
                class="scroe_input"
                v-model="reason"
                rows="4"
                autosize
                type="textarea"
                :placeholder="'请输入'"
                maxlength="100"
                show-word-limit />
            </div>
          </div>
        </div>
      </div>
      <!-- 底部 -->
      <div class="fead_boot">
        <van-button type="info" @click="saveData('1')">提交</van-button>
      </div>
    </div>
  </div>
</template>

<script>
import MyNavBar from '@com/MyNavBar'
import moment from 'moment'
import { addRepair } from '@api/api-dailyManage.js'
export default {
  name: 'repairAdd',
  components: {
    MyNavBar,
  },
  data() {
    return {
      moment: moment,
      userInfo: JSON.parse(localStorage.userInfo),
      applyType: '1',
      timeNow: moment().format('YYYY-MM-DD'),
      model: '',
      reason: '',
    }
  },
  watch: {},
  created() {},
  mounted() {},
  destroyed() {},
  methods: {
    goback() {
      this.$router.go(-1)
    },
    saveData(type) {
      if (this.reason.trim().length === 0) {
        this.$toast.fail('请先填写事由后再提交')
        return
      }
      addRepair({
        model: this.model,
        orgId: this.userInfo.loginPostInfo.orgId,
        reason: this.reason,
        repairMonth: moment().format('M'),
        repairTitle: '物品维修、更换申请单',
        repairType: this.applyType,
        repairYear: moment().format('YYYY'),
        saveStatus: '1',
      }).then(res => {
        if (res.code === 0) {
          this.$toast.success('提交成功')
          setTimeout(() => {
            this.$router.go(-1)
          }, 500)
        }
      })
    },
    radioChange() {},
  },
}
</script>

<style lang="scss" scoped>
.repair_add {
  /deep/ .van-popup {
    position: absolute;
  }
}
.add_con {
  .self_info {
    width: 100%;
    background-color: #ffffff;
    padding: 10px;
    box-shadow: 0 0 10px 0 rgba(4, 0, 0, 0.15);
    border-radius: 5px;
    .self_title_bold {
      font-weight: 800;
      font-size: 14px;
    }
    .correlation_info {
      display: flex;
      justify-content: space-between;
      align-items: center;
      padding: 10px 0;
      border-bottom: 1px solid #efefef;
      .left {
        font-size: 14px;
      }
    }
  }
  .con_box {
    width: 100%;
    background-color: #ffffff;
    padding: 10px;
    box-shadow: 0 0 10px 0 rgba(4, 0, 0, 0.15);
    border-radius: 5px;
    margin-top: 10px;
    .box_head {
      .head_radio {
        padding: 10px 0;
        .van-radio-group {
          .van-radio {
            margin-right: 25px;
          }
        }
      }
    }
    .box_info {
      .info_inpu {
        margin-top: 14px;
        .info_input {
          border: 1px solid #efefef;
          margin-top: 10px;
          .scroe_input {
            padding: 0 5px;
            width: 100%;
            height: auto;
            line-height: 20px;
            font-size: 12px;
            resize: none;
          }
        }
      }
    }
  }
}
</style>
